﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Drawing;
using Pheonix.Fashionzoomer.BLL;
using Pheonix.CodeLibrary;
using Pheonix.CodeLibrary.Web;
using Pheonix.Fashionzoomer.Entity.SqlServer2000;

public partial class page_public_adminlogon : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LoadImages();
    }

    private void LoadImages()
    {
        imgAdminLogo.ImageUrl = "~/App_Themes/" + Page.StyleSheetTheme + "/image/admin-logo.png";
    }

    protected void Login_Click(object sender, EventArgs e)
    {
        string username = Utility.FilterInputText(tbxUsername.Text);
        string password = Utility.FilterInputText(tbxPassword.Text);

        CurrentUser currentUser =  UserManager.LogonUser(username, password);
        if (currentUser != null)
        {
            Pheonix.Fashionzoomer.Entity.SqlServer2000.Membership userMembership = Pheonix.Fashionzoomer.Entity.SqlServer2000.Membership.GetMembershipById(currentUser.MembershipId);
            if (userMembership !=null && userMembership.PackageName.ToLower().Contains("admin"))
            {
                SessionManager.LoggedAdminUser = currentUser;
                Response.Redirect("~/admin/adminhome.aspx");
            }
        }
        CustomValidator validator = new CustomValidator();
        validator.IsValid = false;
        validator.ErrorMessage="Username or password is invalid!";
        Page.Validators.Add(validator);
    }
}
